

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Contracts.Interfaces;
    using Resources;
    using System.Linq;

    
    public sealed class MediumMagneticWeaponCycleTime<T> : FeatureBase<object>
    {
        public MediumMagneticWeaponCycleTime(){}

        public MediumMagneticWeaponCycleTime(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Cycle time"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.Specific; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.MediumMagneticWeaponCycleTime; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_sec; } }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            // Bonus from extensions without RobotControl
            // Bonus from RobotControl extension
            var temp = (double)Value
                / (1 + Math.Abs(agent.Extensions.Where(e => e.Group != ExtensionGroupsEnum.RobotControl).SumModifiersValues(FeatureTypesEnum.Module, this.FeatureType)))
                / (1 + Math.Abs(agent.Extensions.Where(e => e.Group == ExtensionGroupsEnum.RobotControl).SumModifiersValues(FeatureTypesEnum.Module, this.FeatureType)));

            // Bonus from robot
            temp /= 1 + Math.Abs(robot.Modifiers.SumModifiersValues(agent.Extensions, FeatureTypesEnum.Module, this.FeatureType));

            // Bonus from Tunning modules
            temp = robot.Modules.Aggregate(
                temp,
                (current, mod) => current - (current * Math.Abs(mod.Value)),
                FeatureTypesEnum.Module,
                this.FeatureType,
                ModuleGroupsEnum.WeaponTunings);

            ModifiedValue = IsRounded
                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                : Math.Round(temp, 2);
        }

    }
}